<?php
/**
 * Created by PhpStorm. User: ADun, Date: 14/11/16 下午8:23
 * Description:
 */

require_once '../tools/tools.common.php';
require_once Encoding('../system.MsgRouter.php');
include_once Encoding('../system.UIShujuZhongxin.php');
include_once '../linhe.BusinessObject.php';

$pageName=false;
$openId=false;
$action=false;

if(array_key_exists('p',$_REQUEST))
        $pageName=$_REQUEST['p'];
//if(array_key_exists('openId',$_REQUEST))
    $openId=$_REQUEST['oid'];
if(array_key_exists('a',$_REQUEST))
    $action=$_REQUEST['a'];

$outObj=new BoResult();
$out=json_encode($outObj);
if(!$action){
    echo $out;
    return;
}


$data=array();
$bm=new CUI数据中心(Page::action,$openId);
switch($action){
    case Constants::action聊天:
        if(array_key_exists('uid',$_REQUEST))
            $uid=$_REQUEST['uid'];
        else
            $uid=false;

        if($uid) {
            $bm->f关闭会话();
            $data = $bm->startChat($uid);
            if($data==2) {
                $arr['msg'] =   '该店铺,微信暂无信号!请联系其他店铺!';
                $arr['error'] = 1;
            }else if($data) {
                $arr['msg'] =   '会话开启,请点击返回微信开始聊天!';
            } else {
                $arr['msg'] =   '开启会话失败!';
            }
        }else{
            $arr['msg'] =   '无效用户id!';
        }
        Cx消息路由::ff处理返回堆栈();
        $out=json_encode($arr);
        echo $out;
        break;
    case 'makeTop':
        $置顶结果 = $bm->本店推广文章置顶($_REQUEST['sid'],$_REQUEST['店铺id']);
        echo $置顶结果;
        break;
    case 'madecard':
        $va参数 = array();
        $va参数['kid'] = $_REQUEST['kid'];
        $va参数['mname'] = $_REQUEST['mname'];
        $va参数['mid'] = $_REQUEST['mid'];
        $va参数['publicnumber'] = $_REQUEST['publicnumber'];
        $state=Tools::pack参数打包($_REQUEST['type'],$va参数);
        $arr['url']=G_SITE_BASE.'/business/index.php?state='.$state;
        $out=json_encode($arr);
        echo $out;
        break;
    case 'newsHistory':
        $pageNum = intval($_REQUEST['page']);
        if($pageNum<=0){
            $pageNum = 1;
        }
        $start = $pageNum*10-1;
        $sql = "select id,date_format(添加时间,'%Y-%m-%d') as 添加时间 from 咨询信息 where 发送='已发送' order by id desc  limit $start,10";
        $res = pdo()->selectAll($sql);
        if(count($res)<=0){
            echo "zero";
            break;
        }
        foreach($res as $key => $item){
            $sql = "select * from 咨询详情 where 咨询id=".$item['id']." order by 排序 asc";
            $res[$key]['item'] =  pdo()->selectAll($sql);
        }

        foreach($res as $k => $v){
                  $str.="<div class='LoveRead_time'><div>{$v['添加时间']}</div></div><dl>";
                             foreach($v['item'] as $key => $val){
                                if($key == 0){
                                    $str .= "<a href='".$val['文章url']."'><dt><div class='img' style='background:url(".$val['图片url'].") no-repeat center;background-size:cover;'><div><h1>".$val['标题']."</h1></div></div></dt></a>";
                                }else{
                                    $str .= "<a href='".$val['文章url']."'><dd><table><tr><td class='LRtxt'>{$val['标题']}</td><td><div class='img' style=background:url(".$val['图片url'].")  no-repeat center;background-size:cover;'></div></td></tr></table></dd></a>";
                                 }
                            }
                 $str.= "</dl>";
        }
        echo $str;
        break;
    default:
        $arr['msg'] =   'serve error！';
        $out=json_encode($arr);
        echo $out;
}

